package org.bai.meetingfilm.exception;

import org.bai.meetingfilm.common.vo.BaseResponseVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@Component
@ControllerAdvice
public class BaseExceptionHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseExceptionHandler.class);

    @ResponseBody
    @ExceptionHandler(CommonServiceException.class)
    private BaseResponseVO<Object> serviceExceptionHandler(HttpServletRequest request, CommonServiceException exception) {
        LOGGER.error("CommonServiceException, code[{}], message [{}]", exception.getCode(), exception.getMessage());
        return BaseResponseVO.serviceException(exception);
    }
}
